(function() {
    angular.module('app').controller('settingCtrl', settingCtrl);

    settingCtrl.$inject = ['$rootScope', 'atomicNotifyService'];

    function settingCtrl($rootScope, atomicNotifyService) {
        var vm = this;

        vm.user = $rootScope.userInfo;

        vm.tab = {
            cur: 'user',
            change: function(tab) {
                this.cur = tab;
            }
        };

        //反馈
        vm.feedBack = {
            module: '',
            content: '',
            send: _send
        }

        //数据定制
        vm.custom = {
            mobile: '',
            qq: '',
            msg: '',
            send: custom_send
        };

        

        vm.industrySelect = _industrySelect;


        function _industrySelect (){

            if(vm.user.categoryUpdateTime == 0){
                // console.log('本月的重置次数已用完');
                
                atomicNotifyService.info('本月的重置次数已用完');
                return;
            }

            $rootScope.$emit('industry_select_EV');
        }

        function _send() {

            if (this.module == '') {
                atomicNotifyService.info('请选择一个模块');
                return;
            }
            if (this.content == '') {
                atomicNotifyService.info('请填写反馈信息');
                return;
            }

            var msg = JSON.stringify({
                module: this.module,
                content: this.content
            });

            util.$post({
                url: '/marketconditions/feedback/addFeedback.htm',
                data: {
                    msg: msg
                }
            }).then(function(resp) {

                atomicNotifyService.success("发送成功");
                vm.feedBack.module = '';
                vm.feedBack.content = '';


            }, function(err) {
                atomicNotifyService.error("发送失败");
            });


        }

        function custom_send() {
            // console.log(this);

            if (this.qq == '' && this.mobile == '') {
                atomicNotifyService.info("请您任选一个联系方式!");
                return;
            }

            if (this.mobile != '' && !(/^1[34578]\d{9}$/.test(this.mobile))) {

                atomicNotifyService.info("手机号码格式错误");
                return;
            }



            if (this.msg == "") {
                atomicNotifyService.info("请填写您的定制需求");
                return;
            }

            var contactInfo = JSON.stringify({
                qq: this.qq,
                mobile: this.mobile
            });


            util.$get({
                url: '/marketconditions/feedback/addCustomDemand.htm',
                data: {
                    msg: this.msg,
                    contactInfo: contactInfo
                }
            }).then(function() {
                atomicNotifyService.success("发送成功");
                vm.custom.mobile = '';
                vm.custom.qq = '';
                vm.custom.msg = '';

            });
        }
    }
})();
